package com.yicong.ants.ui.scenic;

import androidx.databinding.library.baseAdapters.BR;
import androidx.recyclerview.widget.GridLayoutManager;

import com.cchao.simplelib.core.JsonHelper;
import com.cchao.simplelib.core.Router;
import com.cchao.simplelib.core.UiHelper;
import com.cchao.simplelib.ui.activity.BaseTitleBarActivity;
import com.cchao.simplelib.ui.adapter.DataBindQuickAdapter;
import com.yicong.ants.Constants;
import com.yicong.ants.R;
import com.yicong.ants.bean.scenic.AddedItem;
import com.yicong.ants.bean.scenic.ScenicDetailBean;
import com.yicong.ants.databinding.RecylerBinding;
import com.yicong.ants.manager.config.ZzConfigs;

/**
 * @author cchao
 * @version 2019-11-08.
 */
public class AddedProjectListActivity extends BaseTitleBarActivity<RecylerBinding> {
    ScenicDetailBean mDetailBean;
    DataBindQuickAdapter<AddedItem> mAdapter;

    @Override
    protected int getLayout() {
        return R.layout.recyler;
    }

    @Override
    protected void initEventAndData() {
        mDetailBean = JsonHelper.toObject(getIntent().getStringExtra(Constants.Extra.JSON), ScenicDetailBean.class);
        setTitleText(mDetailBean.getName() + " - 娱乐项目");
        initAdapter();
        mAdapter.setNewData(mDetailBean.getAdded_projects());
    }

    private void initAdapter() {
        mDataBind.recycler.setPadding(UiHelper.dp2px(10), UiHelper.dp2px(10), UiHelper.dp2px(10), 0);
        mDataBind.recycler.setLayoutManager(new GridLayoutManager(mContext, 3));
        mDataBind.recycler.setNestedScrollingEnabled(false);
        mAdapter = new DataBindQuickAdapter<AddedItem>(R.layout.item_scenic_detail_added, null) {
            @Override
            protected void convert(DataBindQuickAdapter.DataBindViewHolder helper, AddedItem item) {
                helper.getBinding().setVariable(BR.bean, item);
//                ImageHelper.loadImageRound(helper.getView(R.id.image), item.getThumbnail(), 4);
            }
        };
        mAdapter.bindToRecyclerView(mDataBind.recycler);
        mAdapter.setOnItemClickListener((adapter, view, position) -> {
            //
            Router.turnTo(mContext, AddedDetailActivity.class)
                .putExtra(Constants.Extra.JSON, JsonHelper.toJson(adapter.getData().get(position)))
                .putExtra(Constants.Extra.JSON2, JsonHelper.toJson(mDetailBean))
                .start();
        });
        mDataBind.recycler.addItemDecoration(ZzConfigs.mTourismRecItemDecoration);
    }

    @Override
    protected void onLoadData() {

    }
}
